<%@ page language="java" import="java.util.*"  %>
<%@ page import="com.hospital.util.DbUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="images/main.css" rel="stylesheet" type="text/css" />
<link  href="../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/trim.js"></script>
<script language="javascript" type="text/javascript" src="../My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	function validate(userfield) {
		if (trim(userfield.value).length != 0) {
			var xmlHttpRequest = null;
			var url = "../AccountIsExistServlet?account=" + userfield.value;
			var usermsg = document.getElementById("usermsg");
			if (window.XMLHttpRequest) {//表示当前浏览器不是IE
				xmlHttpRequest = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlHttpRequest.open("GET", url, true);//设置请求方式为GET，设置请求的URL，设置为异步提交
			xmlHttpRequest.onreadystatechange = function(){//将方法地址复制给onreadystatechange属性
				if(xmlHttpRequest.readyState == 4){//Ajax引擎状态为成功
					if(xmlHttpRequest.status == 200){//HTTP协议状态为成功
						if(trim(xmlHttpRequest.responseText) != ""){
							usermsg.innerHTML = "<font color='red'>" + trim(xmlHttpRequest.responseText) + "</font>";
							userfield.focus();
						}else{
							usermsg.innerHTML = "恭喜您，用户名可以使用。 ";
						}
					}else{
						alert("请求失败，错误码=" + xmlHttp.status);
					}
				}
			};
			xmlHttpRequest.send(null);//将设置信息发送到Ajax引擎
		}else{
			usermsg.innerHTML = "";
		}
	}
	function sub(){
		var username = document.getElementById("username");
		var password = document.getElementById("password");
		var birthday = document.getElementById("birthday");
		var address  = document.getElementById("address");
		var tel = document.getElementById("tel");
		var school = document.getElementById("school");
		var education = document.getElementById("education");
		if(trim(username.value).length == 0){
			alert("用户名不能为空。");
			username.focus();
		}else if(usermsg.innerHTML.length != 13){
			alert("用户已经存在。");
			username.focus();
		}else if(trim(password.value).length == 0){
			alert("密码不能为空。");
			password.focus();
		}else if(trim(password.value).length < 6){
			alert("密码位数必须在6位以上");
			password.focus();
		}else if(trim(password.value).length > 10){
			alert("密码位数必须在10位以下。");
			password.focus();
		}else if(trim(address.value).length == 0){
			alert("地址不能为空。");
			address.focus();
		}else if(trim(tel.value).length == 0){
			alert("电话号码不能为空。");
			tel.focus();
		}else if(!trim(tel.value).length == 11){
			alert("请您输入11位手机号码。");
			tel.focus();
		}else if(isNaN(tel.value)){
			alert("电话号码只能为数字。");
			tel.focus();
		}else if(trim(school.value).length == 0){
			alert("学校不能为空。");
			school.focus();
		}else if(trim(education.value).length == 0){
			alert("教育情况不能为空。");
			education.focus();
		}else{
			document.forms["form"].submit();
		}
	}
	//实现二级联动
	var req;
    window.onload=function(){//页面加载时的函数
    };
    function Change_Select(){//当第一个下拉框的选项发生改变时调用该函数
      var root = document.getElementById('root').value;
      var url = "../SelectServletByUser?root="+ escape(root);
      if(window.XMLHttpRequest){
        req = new XMLHttpRequest();
      }else if(window.ActiveXObject){
        req = new ActiveXObject("Microsoft.XMLHTTP");
      }
      if(req){
        req.open("GET",url,true);
        //指定回调函数为callback
        req.onreadystatechange = callback;
        req.send(null);
      }
    }
    //回调函数
    function callback(){
      if(req.readyState ==4){
        if(req.status ==200){
          parseMessage();//解析XML文档
        }else{
          alert("不能得到描述信息:" + req.statusText);
        }
      }
    }
    //解析返回xml的方法
    function parseMessage(){
      var xmlDoc = req.responseXML.documentElement;//获得返回的XML文档
      var xSel = xmlDoc.getElementsByTagName("select");
      //获得XML文档中的所有<select>标记
      var select_root = document.getElementById("name");
      //获得网页中的第二个下拉框
      select_root.options.length=0;
      //每次获得新的数据的时候先把每二个下拉框架的长度清0
     
      for(var i=0;i<xSel.length;i++){
        var xValue = xSel[i].childNodes[0].firstChild.nodeValue;
        //获得每个<select>标记中的第一个标记的值,也就是<value>标记的值
        var xText = xSel[i].childNodes[1].firstChild.nodeValue;
        //获得每个<select>标记中的第二个标记的值,也就是<text>标记的值
       
        var option = new Option(xText, xValue);
        //根据每组value和text标记的值创建一个option对象
       
        try{
          select_root.add(option);//将option对象添加到第二个下拉框中
        }catch(e){
        }
      }
    }
</script>
</head>
<body onload="init();">
	<jsp:include page="right_top.jsp"></jsp:include>
	<!-- TOP START -->
	<div id="right_font">
		<img src="images/main_14.gif" /> 您现在所在的位置：首页 → 用户信息管理 → <span
			class="bfont">添加用户信息</span>
	</div>
	<!-- TOP END -->
	<hr >
	<form action="UserInfoServlet?method=add" method="post" name="form" id="form">
		<table style="margin-top: 30px;">
			<tr height="30px;">
				<td><font color="#FF0000">*</font>用户名：</td>
				<td><input type="text" name="account" id="username" maxlength="12" onblur="validate(this)"/></td>
				<td width="220px;"><span id="usermsg"></span></td>
			</tr>
			<tr height="30px;">
				<td><font color="#FF0000">*</font>密&nbsp;&nbsp;码：</td>
				<td><input type="password" name="pswd" id="password" maxlength="12" /></td>
				<td>&nbsp;</td>
			</tr>
			<tr height="30px;">
				<td><font color="#FF0000">*</font>角&nbsp;&nbsp;色：</td>
				<td>
					<select name="root" id="root" onclick="Change_Select()">
						<option value="2">在职医生</option>
						<option value="3">在职护士</option>
						<option value="4">窗口挂号</option>
						<option value="7_1">药物基础信息管理</option>
						<option value="7_2">药品进销管理</option>
						<option value="8_1">财务管理人员</option>
						<option value="8_2">财务会计人员</option>
					</select>
				</td>
			</tr>
			<tr height="30px;">
				<td><font color="#FF0000">*</font>性&nbsp;&nbsp;别：</td>
				<td>
					<input type="radio" name="sex" value="男" checked="checked"/> 男&nbsp;&nbsp;
					<input type="radio" name="sex" value="女" /> 女&nbsp;&nbsp;
				</td>
				<td>&nbsp;</td>
			</tr>
			<tr height="30px;">
				<td><font color="#FF0000">*</font>出生日期：</td>
				<td><input id="d11" name="birthday" type="text" onClick="WdatePicker()"/></td>
				<td>&nbsp;</td>
			</tr>
			<tr height="30px;">
				<td><font color="#FF0000">*</font>地&nbsp;&nbsp;址：</td>
				<td><input type="text" name="address" id="address" maxlength="20" /></td>
				<td>&nbsp;</td>
			</tr>
			<tr height="30px;">
				<td><font color="#FF0000">*</font>电&nbsp;&nbsp;话：</td>
				<td><input type="text" name="tel" id="tel" maxlength="12" /></td>
				<td>&nbsp;</td>
			</tr>
			<tr height="30px;">
				<td><font color="#FF0000">*</font>毕业学校：</td>
				<td><input type="text" name="school" id="school" maxlength="12" /></td>
				<td>&nbsp;</td>
			</tr>
			<tr height="30px;">
				<td><font color="#FF0000">*</font>学&nbsp; 历：</td>
				<td>
					<select name="education" id="education">
						<option value="专科">专科毕业</option>
						<option value="本科">本科毕业</option>
						<option value="硕士">硕士毕业</option>
						<option value="博士">博士毕业</option>
						<option value="高中">高中毕业</option>
					</select>
				</td>
				<td>&nbsp;</td>
			</tr>
			<tr height="30px;">
				<td><font color="#FF0000">*</font>部&nbsp;&nbsp;门：</td>
				<td>
					<select name="name" id="name">
					<%-- <% 
						//添加进入DeptId号码
						String sql = "select * from t_department";
						List<Map<String, Object>> list = DbUtil.find(sql);
						Map<String, Object> map = null;
						for (int i = 0; i < list.size(); i++) {
							map = (Map<String, Object>)list.get(i);
					%>
						<option value="<%=map.get("name")%>"><%=map.get("name") %></option>
					<% 
						}
					%> --%>
					</select>
				</td>
				<td>&nbsp;</td>
			</tr>
<!-- 		<tr height="30px;">
				<td><font color="#FF0000">*</font>上传照片：</td>
				<td><input name='photo' type='text' id='photo' size='50' value='' />&nbsp;<input type='button' value='上传' onClick="up('photo')"/></td>
				<td>&nbsp;</td>
			</tr> -->
			<tr height="30px;">
				<td colspan="2" align="center">
					&nbsp;
				</td>
				<td>&nbsp;</td>
			</tr>
			<tr height="30px;">
				<td colspan="2" align="center">
					<input type="button" value="提交" onclick="sub();"/>&nbsp;&nbsp;
					<input type="button" value="返回" onclick="history.go(-1);" />
				</td>
				<td>&nbsp;</td>
			</tr>
		</table>
	</form>
</body>
</html>